#lang racket

;; Includes methods to write a matrix (vector of vectors) and a possibility matrix (vector of vectors of vecotrs)
;; By Theresa Wellington

(provide writeMatrix writePossibilityMatrix)

;; write methods
;;write a matrix (vector1 of vectors) with each vector1 element on a new line
(define writeMatrix
  (lambda (matrix)
    (writeEachMatrixLine matrix 0) (newline) (newline)))

(define writeEachMatrixLine
  (lambda (matrix line)
    (if (equal? line 8) (write (vector-ref matrix line))
        (and (write (vector-ref matrix line)) (newline) (writeEachMatrixLine matrix (+ line 1))))))

;;write the possibilites matrix (vector1 of vectors of vectors) with each vector1 element on a new line
(define writePossibilityMatrix
  (lambda (matrix)
    (writeEachPossibilityMatrixLine matrix 0) (newline)))

(define writeEachPossibilityMatrixLine
  (lambda (matrix line)
    (if (equal? line 8) (writeCellPossibility (vector-ref matrix line))
        (and (writeCellPossibility (vector-ref matrix line)) (newline) (writeEachPossibilityMatrixLine matrix (+ line 1))))))

(define writeCellPossibility
  (lambda (matrixLine)
    (writeEachCellPossibility matrixLine 0)))

(define writeEachCellPossibility
  (lambda (cell pos)
    (if (equal? pos 8) (writeEachCellPossibilityValue (vector-ref cell pos) 0)
        (and (writeEachCellPossibilityValue (vector-ref cell pos) 0) (write '/)  (writeEachCellPossibility cell (+ pos 1))))))

;; change t/f in single vector (cell) to number if true or - if false
(define writeEachCellPossibilityValue
  (lambda (cell pos)
    (if (equal? pos 8) 
        (if (vector-ref cell pos) (write 9)
            (and (write '-)))
        (and 
         (if (vector-ref cell pos) (write (+ pos 1))
             (and (write '-)))
         (writeEachCellPossibilityValue cell (+ pos 1))))))